;-------------------------------------------------------------------------------------
;
;	
;							MiTAC Corporation		
;				NO. 187, TIDING BLVD., SEC. 2, TAIPEI, TAIWAN
;	
; 			(c) Copyright 2006, MiTAC Corporation, Taipei, Taiwan  
;						All rights reserved.
;-------------------------------------------------------------------------------------
;
;
;
;	File:  mmulib.s
;
;	Programer: Visual.Wei 
;	Date: 2006-3-20

        INCLUDE kxarm.h

        TEXTAREA

;-------------------------------------------------------------------------------
;
;  Function:  _page_enable
;
	LEAF_ENTRY _page_enable
        	mcr p15,0,r0,c2,c0,0	;write c2,translation table base
        	mov r0,#0xFFFFFFFF;all domain in manager
        	mcr p15,0,r0,c3,c0,0	;write c3,Domain
	mrc p15,0,r1,c1,c0,0	;Read c1
	orr r1,r1,#0x1		;set M bit
	mcr p15,0,r1,c1,c0,0	;write c1,enable MMU
	nop
	nop
	nop
	bx          lr
;-------------------------------------------------------------------------------
;
;  Function:  _page_disable
;
	LEAF_ENTRY _page_disable

	mrc p15,0,r1,c1,c0,0	;Read c1
	bic r1,r1,#0x1		;set M bit
	mcr p15,0,r1,c1,c0,0	;write c1,disable MMU
	nop
	nop
	nop
	bx          lr
;------------------------------------------------------------------------------
;
;  Function:  _arm9_deep_sleep
;
	LEAF_ENTRY _arm9_deep_sleep

	mov r0,#0
	mcr p15,0,r0,c7,c0,4	;wait for interrupt
	nop
	nop
	nop
	bx          lr
;------------------------------------------------------------------------------
;====================================
; MMU Cache/TLB/etc on/off functions
;====================================
R1_I	EQU	(1<<12)
R1_C	EQU	(1<<2)
R1_A	EQU	(1<<1)
R1_M    EQU	(1)
R1_IA	EQU	(1<<31)
R1_NF   EQU	(1<<30)	

;-------------------------------------------------------------------------------
;
; Function: void _EnableICache(void)
;
	LEAF_ENTRY _EnableICache
	mrc p15,0,r0,c1,c0,0
	orr r0,r0,#R1_I
	mcr p15,0,r0,c1,c0,0
	bx lr
;-------------------------------------------------------------------------------
;
; Function: void _DisableICache(void)
;
	LEAF_ENTRY _DisableICache
	mrc p15,0,r0,c1,c0,0
	bic r0,r0,#R1_I
	mcr p15,0,r0,c1,c0,0
	bx lr
;-------------------------------------------------------------------------------
;
; Function: void _EnableDCache(void)
;
	LEAF_ENTRY _EnableDCache
	mrc p15,0,r0,c1,c0,0
	orr r0,r0,#R1_C
	mcr p15,0,r0,c1,c0,0
	bx lr
;-------------------------------------------------------------------------------
;
; Function: void _DisableDCache(void)
;
	LEAF_ENTRY _DisableDCache
	mrc p15,0,r0,c1,c0,0
	bic r0,r0,#R1_C
	mcr p15,0,r0,c1,c0,0
	bx lr	

;-------------------------------------------------------------------------------
;	
;  Function: void _InvalidateIDCache(void)
;
	LEAF_ENTRY _InvalidateIDCache
   	mcr p15,0,r0,c7,c7,0
	bx lr

;-------------------------------------------------------------------------------
;
;  Function: void _InvalidateICache(void)
;
	LEAF_ENTRY _InvalidateICache
	mcr p15,0,r0,c7,c5,0
   	bx lr
;-------------------------------------------------------------------------------
;
;  Function: void _InvalidateDCache(void)
;
	LEAF_ENTRY _InvalidateDCache
	mcr p15,0,r0,c7,c6,0
   	bx lr   	

;-------------------------------------------------------------------------------
;
;  Function: void _InvalidateTLB(void)
;
	LEAF_ENTRY _InvalidateTLB
	mcr p15,0,r0,c8,c7,0
   	bx lr     
        END
